l-137 ol-137"> 144 207
     private void noMedia(){
145 208
         File noMedia = new File(Constants.APP_ROOT_DIR,".nomedia");

+ 16 - 2
app/src/main/java/ai/pai/lensman/dslr/CameraJNIInterface.java

@@ -2,14 +2,28 @@ package ai.pai.lensman.dslr;
2 2
 
3 3
 public class CameraJNIInterface {
4 4
 
5
+
5 6
     static {
6
-        System.loadLibrary("");
7
+        System.loadLibrary("hello_jni");
8
+    }
9
+
10
+    private static CameraJNIInterface instance;
11
+
12
+    private CameraJNIInterface(){
13
+
14
+    }
15
+
16
+    public static synchronized CameraJNIInterface getInstance(){
17
+        if(instance==null){
18
+            instance = new CameraJNIInterface();
19
+        }
20
+        return instance;
7 21
     }
8 22
 
9 23
     public native  int  mygpcamerainit();
10 24
     public native  int  mygpcameraexit();
11 25
     public native  String  mygpcameragetsummary();
12
-    public native  int  mygpcamerawaitforevent(String  foldr_path, String file_name);
26
+    public native  String  mygpcamerawaitforevent(String  foldr_path);
13 27
     public native  int  mygpfilenewfromfd(String  file_path);
14 28
     public native  int  mygpcamerafileget(String  foldr_path, String file_name);
15 29
     public native  int  mygpfilefree();

+ 55 - 3
app/src/main/java/ai/pai/lensman/login/LoginActivity.java

@@ -1,22 +1,27 @@
1 1
 package ai.pai.lensman.login;
2 2
 
3 3
 import android.content.Intent;
4
-import android.graphics.Paint;
5 4
 import android.os.Bundle;
6 5
 import android.support.v4.app.FragmentActivity;
7
-import android.text.Html;
8 6
 import android.text.SpannableString;
9 7
 import android.text.TextUtils;
10 8
 import android.text.style.UnderlineSpan;
11 9
 import android.view.View;
10
+import android.widget.ImageView;
12 11
 import android.widget.TextView;
13 12
 import android.widget.Toast;
14 13
 
14
+import com.android.common.utils.LogHelper;
15 15
 import com.android.views.progressbar.ProgressWheel;
16 16
 
17
+import java.io.File;
18
+
17 19
 import ai.pai.lensman.R;
18 20
 import ai.pai.lensman.activities.WebViewActivity;
21
+import ai.pai.lensman.dslr.CameraJNIInterface;
19 22
 import ai.pai.lensman.main.MainActivity;
23
+import ai.pai.lensman.service.Constants;
24
+import ai.pai.lensman.utils.ImageLoaderUtils;
20 25
 import butterknife.BindView;
21 26
 import butterknife.ButterKnife;
22 27
 import butterknife.OnClick;
@@ -25,8 +30,9 @@ public class LoginActivity extends FragmentActivity implements LoginContract.Vie
25 30
 
26 31
     @BindView(R.id.wheel_wait_http)    ProgressWheel progressWheel;
27 32
     @BindView(R.id.tv_agree_protocol)  TextView protocolText;
28
-
33
+    @BindView(R.id.iv_login_logo)      ImageView photoView;
29 34
     private LoginContract.Presenter presenter;
35
+    private boolean isCancelled;
30 36
 
31 37
     @Override
32 38
     protected void onCreate(Bundle savedInstanceState) {
@@ -37,8 +43,47 @@ public class LoginActivity extends FragmentActivity implements LoginContract.Vie
37 43
         content.setSpan(new UnderlineSpan(), 6, content.length(), 0);
38 44
         protocolText.setText(content);
39 45
         presenter = new LoginPresenter(this,this);
46
+        int ret = CameraJNIInterface.getInstance().mygpcamerainit();
47
+        if(ret>=0){
48
+            String text = CameraJNIInterface.getInstance().mygpcameragetsummary();
49
+            LogHelper.d("czy","text="+text);
50
+            protocolText.setText("text="+text);
51
+//            Toast.makeText(this,text,Toast.LENGTH_LONG).show();
52
+        }else{
53
+            LogHelper.d("czy","ret="+ret);
54
+//            Toast.makeText(this,"camera init return "+ret,Toast.LENGTH_LONG).show();
55
+            protocolText.setText("camera init return "+ret);
56
+        }
57
+        File dir = new File(Constants.APP_IMAGE_DIR);
58
+        dir.mkdirs();
59
+        fetchPhotoTask();
40 60
     }
41 61
 
62
+    private void fetchPhotoTask(){
63
+        new Thread(new Runnable() {
64
+            @Override
65
+            public void run() {
66
+                while (!isCancelled){
67
+                    final String photoName = CameraJNIInterface.getInstance().mygpcamerawaitforevent(Constants.APP_IMAGE_DIR);
68
+                    LogHelper.d("czy","mygpcamerawaitforevent return "+photoName);
69
+                    photoView.post(new Runnable() {
70
+                        @Override
71
+                        public void run() {
72
+                            protocolText.setText("mygpcamerawaitforevent return "+photoName);
73
+                            if(photoName!=null && photoName.length()>0){
74
+                                String sub = photoName.substring(0,1);
75
+                                if(TextUtils.isDigitsOnly(sub)){
76
+                                    ImageLoaderUtils.displayLocalImage(Constants.APP_IMAGE_DIR+File.separator+photoName,photoView,ImageLoaderUtils.getOptions(R.drawable.login_page_logo));
77
+                                }
78
+                            }
79
+
80
+                        }
81
+                    });
82
+                }
83
+            }
84
+        }).start();
85
+
86
+    }
42 87
 
43 88
     @Override
44 89
     protected void onResume() {
@@ -46,6 +91,13 @@ public class LoginActivity extends FragmentActivity implements LoginContract.Vie
46 91
         presenter.start();
47 92
     }
48 93
 
94
+    @Override
95
+    protected void onDestroy() {
96
+        super.onDestroy();
97
+        CameraJNIInterface.getInstance().mygpcameraexit();
98
+        isCancelled = true;
99
+    }
100
+
49 101
     @OnClick(R.id.btn_login)
50 102
     public void login(){
51 103
         presenter.login();

+ 12 - 1
app/src/main/java/ai/pai/lensman/session/SessionInteractor.java

@@ -1,15 +1,19 @@
1 1
 package ai.pai.lensman.session;
2 2
 
3
+import android.widget.Toast;
4
+
3 5
 import com.android.common.utils.LogHelper;
4 6
 
5 7
 import java.util.ArrayList;
6 8
 import java.util.Timer;
7 9
 import java.util.TimerTask;
8 10
 
11
+import ai.pai.lensman.App;
9 12
 import ai.pai.lensman.BuildConfig;
10 13
 import ai.pai.lensman.bean.PhotoBean;
11 14
 import ai.pai.lensman.bean.SessionBean;
12 15
 import ai.pai.lensman.db.DBService;
16
+import ai.pai.lensman.dslr.CameraJNIInterface;
13 17
 
14 18
 public class SessionInteractor {
15 19
 
@@ -55,6 +59,12 @@ public class SessionInteractor {
55 59
     }
56 60
 
57 61
     public void startCapture() {
62
+        int result = CameraJNIInterface.getInstance().mygpcamerainit();
63
+        if(result>=0){
64
+            LogHelper.d(TAG,"相机信息--->\n"+CameraJNIInterface.getInstance().mygpcameragetsummary());
65
+            Toast.makeText(App.getAppContext(),CameraJNIInterface.getInstance().mygpcameragetsummary(),Toast.LENGTH_SHORT).show();
66
+
67
+        }
58 68
         if(timer!=null){
59 69
             timer.cancel();
60 70
             timer = null;
@@ -65,13 +75,14 @@ public class SessionInteractor {
65 75
             public void run() {
66 76
                 fetchPhotoTask();
67 77
             }
68
-        },5000,2000);
78
+        },5000,1000);
69 79
     }
70 80
 
71 81
     private void fetchPhotoTask(){
72 82
         if(!isWorking){
73 83
             return;
74 84
         }
85
+
75 86
         if(!isLastQueryReturned){
76 87
             return;
77 88
         }

BIN
app/src/main/res/raw/camera.so


+ 110 - 0
common/src/main/java/com/android/common/utils/FileUnzipTask.java

@@ -0,0 +1,110 @@
1
+package com.android.common.utils;
2
+
3
+import android.os.AsyncTask;
4
+
5
+import java.io.File;
6
+import java.io.FileOutputStream;
7
+import java.io.InputStream;
8
+import java.io.OutputStream;
9
+import java.util.Enumeration;
10
+import java.util.zip.ZipFile;
11
+
12
+/**
13
+ * zip文件解压缩任务,支持zip内多级目录结构
14
+ *
15
+ * Created By chengzhenyu
16
+ */
17
+public class FileUnzipTask {
18
+
19
+    private String unZipDir;
20
+    private String zipFilePath;
21
+    private AsyncTask unzipTask;
22
+    private FileUnzipListener listener;
23
+
24
+    private boolean isCancelled;
25
+
26
+    private static final int BUF_SIZE = 2048;
27
+
28
+    private static final String TAG = "FileUnzipTask";
29
+
30
+    public interface FileUnzipListener {
31
+        void onUnzipSuccess(String zipFilePath, String unZipDir);
32
+        void onUnzipError(int errorCode, String zipFilePath, String unZipDir);
33
+    }
34
+
35
+    public FileUnzipTask(String zipFilePath, String unZipDir, FileUnzipListener listener) {
36
+        this.listener = listener;
37
+        this.unZipDir = unZipDir;
38
+        this.zipFilePath = zipFilePath;
39
+    }
40
+
41
+    public void startUnZip() {
42
+        isCancelled = false;
43
+
44
+        unzipTask = new AsyncTask<Object, Integer, Boolean>() {
45
+
46
+            @Override
47
+            protected Boolean doInBackground(Object... params) {
48
+                try {
49
+                    File desDir = new File(unZipDir);
50
+                    if (!desDir.exists()) {
51
+                        desDir.mkdirs();
52
+                    }
53
+                    ZipFile zf = new ZipFile(zipFilePath);
54
+                    for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements();) {
55
+                        if(isCancelled){
56
+                            break;
57
+                        }
58
+                        java.util.zip.ZipEntry entry = ((java.util.zip.ZipEntry)entries.nextElement());
59
+                        InputStream in = zf.getInputStream(entry);
60
+                        String str = unZipDir + File.separator + entry.getName();
61
+                        str = new String(str.getBytes("8859_1"), "GB2312");
62
+                        File desFile = new File(str);
63
+                        if (!desFile.exists()) {
64
+                            File fileParentDir = desFile.getParentFile();
65
+                            if (!fileParentDir.exists()) {
66
+                                fileParentDir.mkdirs();
67
+                            }
68
+                            if(entry.isDirectory()){
69
+                                desFile.mkdirs();
70
+                                continue;
71
+                            }else{
72
+                                desFile.createNewFile();
73
+                            }
74
+                        }
75
+                        OutputStream out = new FileOutputStream(desFile);
76
+                        byte buffer[] = new byte[BUF_SIZE];
77
+                        int realLength;
78
+                        while ((realLength = in.read(buffer)) > 0) {
79
+                            out.write(buffer, 0, realLength);
80
+                        }
81
+                        in.close();
82
+                        out.close();
83
+                    }
84
+                    return true;
85
+                } catch (Exception e) {
86
+                    e.printStackTrace();
87
+                }
88
+                return false;
89
+            }
90
+
91
+            @Override
92
+            protected void onPostExecute(Boolean result) {
93
+                LogHelper.d(TAG, "unzip task onPostExecute result=" + result);
94
+                if (result) {
95
+                    listener.onUnzipSuccess(zipFilePath, unZipDir);
96
+                } else {
97
+                    listener.onUnzipError(-1, zipFilePath, unZipDir);
98
+                }
99
+            }
100
+        };
101
+        unzipTask.execute();
102
+    }
103
+
104
+    public void cancelUnzip() {
105
+        if (unzipTask != null) {
106
+            isCancelled = true;
107
+            unzipTask.cancel(true);
108
+        }
109
+    }
110
+}

:art: Refresh phone by membercard info · 644b809983 - Gogs: Go Git Service

:art: Refresh phone by membercard info

huangqimin 6 years ago
parent
commit
644b809983
3 changed files with 104 additions and 1 deletions
  1. 24 0
      api/refresh_views.py
  2. 4 1
      api/urls.py
  3. 76 0
      commands/management/commands/membercard.py

+ 24 - 0
api/refresh_views.py

@@ -0,0 +1,24 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+from __future__ import division
4
+
5
+import json
6
+
7
+from django_logit import logit
8
+from django_response import response
9
+
10
+from account.models import UserInfo
11
+from utils.redis.connect import r
12
+from utils.redis.rkeys import MEMBERCARD_USERINFO_LIST
13
+
14
+
15
+@logit
16
+def phone(request):
17
+    users = UserInfo.objects.filter(phone='').exclude(memberusercardcode='')
18
+
19
+    p = r.pipeline()
20
+    for u in users:
21
+        p.rpush(MEMBERCARD_USERINFO_LIST, json.dumps(u.cardata))
22
+    p.execute()
23
+
24
+    return response()

+ 4 - 1
api/urls.py

@@ -6,7 +6,7 @@ from django_file_upload import views as file_views
6 6
 from account import tourguide_views
7 7
 from account import views as account_views
8 8
 from api import (admin_views, clerk_views, distributor_views, encrypt_views, mch_views, member_views, model_views,
9
-                 operator_views, sr_views, staff_views, log_views)
9
+                 operator_views, refresh_views, sr_views, staff_views, log_views)
10 10
 from box import views as box_views
11 11
 from geo import views as geo_views
12 12
 from group import (groupuser_views, lensman_views, tourguidegroup_views, tourguidegroupadmin_views,
@@ -304,7 +304,10 @@ urlpatterns += [
304 304
     url(r'^admin/statistic/distributor$', admin_views.statistic_distributor, name='statistic_distributor'),
305 305
 
306 306
     url(r'^admin/statistic/deep/analyze$', admin_views.statistic_deep_analyze, name='statistic_deep_analyze'),
307
+]
307 308
 
309
+urlpatterns += [
310
+    url(r'^refresh/phone$', refresh_views.phone, name='phone'),
308 311
 ]
309 312
 
310 313
 urlpatterns += [

+ 76 - 0
commands/management/commands/membercard.py

@@ -0,0 +1,76 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+import logging
4
+
5
+from django.conf import settings
6
+from django.db import transaction
7
+from django_six import CompatibilityBaseCommand, close_old_connections
8
+from pywe_membercard import get_userinfo
9
+from pywe_storage import RedisStorage
10
+
11
+from account.models import UserInfo
12
+from utils.redis.connect import r
13
+from utils.redis.rkeys import MEMBERCARD_USERINFO_LIST
14
+
15
+
16
+WECHAT = settings.WECHAT
17
+
18
+
19
+logger = logging.getLogger('console')
20
+
21
+
22
+def get_phone(fields):
23
+    for field in fields:
24
+        name = field.get('name', '')
25
+        if name == 'USER_FORM_INFO_FLAG_MOBILE':
26
+            return field.get('value', '')
27
+    return ''
28
+
29
+
30
+class Command(CompatibilityBaseCommand):
31
+    def handle(self, *args, **options):
32
+
33
+        logger.info('MemberCard userinfo is dealing')
34
+
35
+        while True:
36
+            # r.rpushjson('MEMBERCARD_USERINFO_LIST', {
37
+            #    'brand_id': 'brand_id',
38
+            #    'card_id': 'card_id',
39
+            #    'code': 'code',
40
+            # })
41
+            k, v = r.blpopjson(MEMBERCARD_USERINFO_LIST, 60)
42
+            if not v:
43
+                continue
44
+
45
+            logger.info(v)
46
+
47
+            brand_id, card_id, code = v.get('brand_id', ''), v.get('card_id', ''), v.get('code', '')
48
+
49
+            if not (card_id and code):
50
+                continue
51
+
52
+            wxcfg = WECHAT.get('{}:JSAPI'.format(brand_id), {})
53
+
54
+            appid = wxcfg.get('appID')
55
+            secret = wxcfg.get('appsecret')
56
+
57
+            userinfo = get_userinfo(card_id, code, appid=appid, secret=secret, storage=RedisStorage(r))
58
+
59
+            logger.info(userinfo)
60
+
61
+            userinfo = userinfo.get('user_info', {})
62
+            if not userinfo:
63
+                continue
64
+
65
+            common_field_list = userinfo.get('common_field_list', [])
66
+            phone = get_phone(common_field_list)
67
+
68
+            if not phone:
69
+                continue
70
+
71
+            close_old_connections()
72
+
73
+            with transaction.atomic():
74
+                UserInfo.objects.select_for_update().filter(membercardid=card_id, memberusercardcode=code).update(phone=phone)
75
+
76
+            close_old_connections()